package com.marktotop.file.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.marktotop.file.entity.TbFile;
import com.marktotop.file.entity.TbUser;
import com.marktotop.file.response.ResultBean;
import com.marktotop.file.service.TbFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author WXLD
 * @data 2021/4/20 - 14:32
 */
@RestController
@Slf4j(topic = "file")
@RequestMapping(value = "/api")
@CrossOrigin
@Api(tags = "文件系统接口")
public class TbFileController {

    @Autowired
    private TbFileService tbFileService;


    /**
     * 获取全部文件信息   分页支持
     * @param pageNum  传入页数
     * @param pageSize 传入每页数量
     * @return
     */
    @RequestMapping(value = "/getAllFile",method = RequestMethod.GET)
    @ApiOperation(value = "获取全部文件信息",notes="获取全部文件信息,get方式")
    public ResultBean getAllFile(@RequestParam(defaultValue = "1",value = "pagenum") Integer pageNum,
                                 @RequestParam(defaultValue = "5",value = "pagesize") Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<TbFile> allFiles = tbFileService.getAllFiles();
        if(allFiles == null){
            return ResultBean.error().message("文件信息获取失败或为空！");
        }
        // 分页支持
        PageInfo<TbFile> filePage = new PageInfo<TbFile>(allFiles);
        return ResultBean.ok().data("files",filePage);
    }



}
